home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-SPAR.{_A / MOSTEK.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  127 lines

  1. /* $Id: mostek.h,v 1.2 1997/03/25 03:58:30 davem Exp $
  2.  * mostek.h:  Describes the various Mostek time of day clock registers.
  3.  *
  4.  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5.  * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
  6.  */
  7.  
  8. #ifndef _SPARC64_MOSTEK_H
  9. #define _SPARC64_MOSTEK_H
  10.  
  11. #include <asm/idprom.h>
  12.  
  13. /*       M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
  14.  *
  15.  *                             Data
  16.  * Address                                                 Function
  17.  *        Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
  18.  *   7ff  -     -     -     -    -     -     -     -       Year 00-99
  19.  *   7fe  0     0     0     -    -     -     -     -      Month 01-12
  20.  *   7fd  0     0     -     -    -     -     -     -       Date 01-31
  21.  *   7fc  0     FT    0     0    0     -     -     -        Day 01-07
  22.  *   7fb  KS    0     -     -    -     -     -     -      Hours 00-23
  23.  *   7fa  0     -     -     -    -     -     -     -    Minutes 00-59
  24.  *   7f9  ST    -     -     -    -     -     -     -    Seconds 00-59
  25.  *   7f8  W     R     S     -    -     -     -     -    Control
  26.  *
  27.  *   * ST is STOP BIT
  28.  *   * W is WRITE BIT
  29.  *   * R is READ BIT
  30.  *   * S is SIGN BIT
  31.  *   * FT is FREQ TEST BIT
  32.  *   * KS is KICK START BIT
  33.  */
  34.  
  35. /* The Mostek 48t02 real time clock and NVRAM chip. The registers
  36.  * other than the control register are in binary coded decimal. Some
  37.  * control bits also live outside the control register.
  38.  */
  39.  
  40. struct mostek48t02 {
  41.     volatile char eeprom[2008];    /* This is the eeprom, don't touch! */
  42.     struct idprom idprom;        /* The idprom lives here. */
  43.     volatile unsigned char creg;    /* Control register */
  44.     volatile unsigned char sec;    /* Seconds (0-59) */
  45.     volatile unsigned char min;    /* Minutes (0-59) */
  46.     volatile unsigned char hour;    /* Hour (0-23) */
  47.     volatile unsigned char dow;    /* Day of the week (1-7) */
  48.     volatile unsigned char dom;    /* Day of the month (1-31) */
  49.     volatile unsigned char month;    /* Month of year (1-12) */
  50.     volatile unsigned char year;    /* Year (0-99) */
  51. };
  52.  
  53. extern struct mostek48t02 *mstk48t02_regs;
  54.  
  55. /* Control register values. */
  56. #define    MSTK_CREG_WRITE    0x80    /* Must set this before placing values. */
  57. #define    MSTK_CREG_READ    0x40    /* Stop updates to allow a clean read. */
  58. #define    MSTK_CREG_SIGN    0x20    /* Slow/speed clock in calibration mode. */
  59.  
  60. /* Control bits that live in the other registers. */
  61. #define    MSTK_STOP    0x80    /* Stop the clock oscillator. (sec) */
  62. #define    MSTK_KICK_START    0x80    /* Kick start the clock chip. (hour) */
  63. #define MSTK_FREQ_TEST    0x40    /* Frequency test mode. (day) */
  64.  
  65. #define MSTK_YEAR_ZERO       1968   /* If year reg has zero, it is 1968. */
  66. #define MSTK_CVT_YEAR(yr)  ((yr) + MSTK_YEAR_ZERO)
  67.  
  68. /* Masks that define how much space each value takes up. */
  69. #define    MSTK_SEC_MASK    0x7f
  70. #define    MSTK_MIN_MASK    0x7f
  71. #define    MSTK_HOUR_MASK    0x3f
  72. #define    MSTK_DOW_MASK    0x07
  73. #define    MSTK_DOM_MASK    0x3f
  74. #define    MSTK_MONTH_MASK    0x1f
  75. #define    MSTK_YEAR_MASK    0xff
  76.  
  77. /* Binary coded decimal conversion macros. */
  78. #define MSTK_REGVAL_TO_DECIMAL(x)  (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
  79. #define MSTK_DECIMAL_TO_REGVAL(x)  ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
  80.  
  81. /* Generic register set and get macros for internal use. */
  82. #define MSTK_GET(regs,var,mask) (MSTK_REGVAL_TO_DECIMAL(regs->var & MSTK_ ## mask ## _MASK))
  83. #define MSTK_SET(regs,var,value,mask) do { regs->var &= ~(MSTK_ ## mask ## _MASK); regs->var |= MSTK_DECIMAL_TO_REGVAL(value) & (MSTK_ ## mask ## _MASK); } while (0)
  84.  
  85. /* Macros to make register access easier on our fingers. These give you
  86.  * the decimal value of the register requested if applicable. You pass
  87.  * the a pointer to a 'struct mostek48t02'.
  88.  */
  89. #define    MSTK_REG_CREG(regs)    (regs->creg)
  90. #define    MSTK_REG_SEC(regs)    MSTK_GET(regs,sec,SEC)
  91. #define    MSTK_REG_MIN(regs)    MSTK_GET(regs,min,MIN)
  92. #define    MSTK_REG_HOUR(regs)    MSTK_GET(regs,hour,HOUR)
  93. #define    MSTK_REG_DOW(regs)    MSTK_GET(regs,dow,DOW)
  94. #define    MSTK_REG_DOM(regs)    MSTK_GET(regs,dom,DOM)
  95. #define    MSTK_REG_MONTH(regs)    MSTK_GET(regs,month,MONTH)
  96. #define    MSTK_REG_YEAR(regs)    MSTK_GET(regs,year,YEAR)
  97.  
  98. #define    MSTK_SET_REG_SEC(regs,value)    MSTK_SET(regs,sec,value,SEC)
  99. #define    MSTK_SET_REG_MIN(regs,value)    MSTK_SET(regs,min,value,MIN)
  100. #define    MSTK_SET_REG_HOUR(regs,value)    MSTK_SET(regs,hour,value,HOUR)
  101. #define    MSTK_SET_REG_DOW(regs,value)    MSTK_SET(regs,dow,value,DOW)
  102. #define    MSTK_SET_REG_DOM(regs,value)    MSTK_SET(regs,dom,value,DOM)
  103. #define    MSTK_SET_REG_MONTH(regs,value)    MSTK_SET(regs,month,value,MONTH)
  104. #define    MSTK_SET_REG_YEAR(regs,value)    MSTK_SET(regs,year,value,YEAR)
  105.  
  106.  
  107. /* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
  108.  * same (basically) layout of the 48t02 chip except for the extra
  109.  * NVRAM on board (8 KB against the 48t02's 2 KB).
  110.  */
  111. struct mostek48t08 {
  112.     char offset[6*1024];         /* Magic things may be here, who knows? */
  113.     struct mostek48t02 regs;     /* Here is what we are interested in.   */
  114. };
  115. extern struct mostek48t08 *mstk48t08_regs;
  116.  
  117. /* SUN5 systems usually have 48t59 model clock chipsets.  But we keep the older
  118.  * clock chip definitions around just in case.
  119.  */
  120. struct mostek48t59 {
  121.     char offset[6*1024];
  122.     struct mostek48t02 regs;
  123. };
  124. extern struct mostek48t59 *mstk48t59_regs;
  125.  
  126. #endif /* !(_SPARC64_MOSTEK_H) */
  127.